//
// Created by zhouyi on 2019/10/26.
//

#include <printf.h>
#include "LearnCpp.h"
#include <iostream>

using namespace std;

#define d1 20

#undef d1

void testCount() {
    char name[50];
    cout << "请输入您的名称： ";
    cin >> name;
    cout << "您的名称是： " << name << endl;
}

struct Teacher2 {
    int &a;
    int &b;
    int age;
};
struct Teacher {
    char name[64];
    int age;
    int &a;
    int &b;

};


int operatorTeacher(const Teacher *pTeacher) {
    // 输入参数 age和name的值不能被改变
    cout << " pTeacher age " << pTeacher->age << endl;
    cout << " pTeacher name " << pTeacher->name << endl;
};

int operatorTeacher2(Teacher *const pTeacher) {
    // 输出参数
    cout << " pTeacher age " << pTeacher->age << endl;
    cout << " pTeacher name " << pTeacher->name << endl;
    pTeacher->age = 20;
};

/**
 * 交换
 * @param a
 * @param b
 * @return
 */
int swap1(int *a, int *b) {// 能交换外部的值
    int tmp = *a;
    *a = *b;
    *b = tmp;
}

int swap2(int &a, int &b) { // 能交换外部的值
    int tmp = a;
    a = b;
    b = tmp;
}


int swap3(int a, int b) { // 不能交换外部的值
    int tmp = a;
    a = b;
    b = tmp;
}


int getA1() {
    int a = 19;
    return a;
}

int &getA2() {
    // 这是有问题的，栈区和堆区
    int a;
    a = 29;
    return a;
}

namespace namespaceTest {
    int age = 30;
}

int main(int argc, char *argv[]) {
//    testCount();
//    cout << namespaceTest::age;

//    bool isOpen = true;
//    isOpen = 19;
//    cout << " isOpen " << isOpen << endl;
//
//    int i = 10;
//    int *const pIntValue1 = &i;
//
//    const int *pIntValue2 = &i;
//    int const *pIntValue3 = &i;


//    int a = 10;
//    int &b = a;
////
//    printf("b: %d\n", b);
//    printf("a: %d\n\n", a);
//
//    printf("&a %p\n", &a);
//    printf("&b %p\n\n", &b);

//
//    b = 100;
//
//    printf("b: %d\n", b);
//    printf("a: %d\n", a);

//    int intA = 10;
//    int intC = 20;
//
//    printf("a: %d  intC: %d\n", intA, intC);
//    swap1(&intA, &intC);
//    printf("a: %d  intC: %d\n\n", intA, intC);
//
//
//    printf("a: %d  intC: %d\n", intA, intC);
//    swap2(intA, intC);
//    printf("a: %d  intC: %d\n\n", intA, intC);
//
//
//    printf("a: %d  intC: %d\n", intA, intC);
//    swap3(intA, intC);
//    printf("a: %d  intC: %d\n\n", intA, intC);
//
//    printf("sizeof a: %lu \n\n", sizeof(int));
//    printf("sizeof a: %lu \n\n", sizeof(a));
//    printf("sizeof a: %lu \n\n", sizeof(&b));
//    printf("sizeof Teacher: %lu \n\n", sizeof(Teacher));
//    printf("sizeof Teacher: %lu \n\n", sizeof(Teacher2));



    cout << getA1() << endl;
    cout << getA2() << endl;





    return 0;
}


